#!/usr/bin/env bash
set -e

exec 2>&1

# defaults
USER=${USER:-www-data}
APP=stern
CONFIG=${CONFIG:-/etc/${APP}/${APP}.yaml}
HOME=${APP_HOME:-/opt/$APP}
BIN=$HOME/bin/$APP

if [ ! -f $CONFIG ]; then exec chpst -u $USER get_config; fi

cd $HOME

ulimit -n 65536

exec chpst -u $USER $BIN --config-file=${CONFIG}
